package client

import (
	"github.com/spf13/cobra"
	"grpc-gateway-demo/client"
	"log"
)

var StartCmd = &cobra.Command{
	Use:   "client",
	Short: "Run the gRPC gateway client",
	Run: func(cmd *cobra.Command, args []string) {
		defer func() {
			if err := recover(); err != nil {
				log.Printf("Recover error:%v\n", err)
			}
		}()
		err := client.Client()
		if err != nil {
			return
		}
	},
}

func init() {
	StartCmd.Flags().StringVarP(&client.Port, "port", "p", "50001", "server port")
	StartCmd.Flags().StringVarP(&client.CertPemPath, "cert-pem", "", "./certs/server.pem", "cert pem path")
	StartCmd.Flags().StringVarP(&client.CertName, "cert-name", "", "grpc.demo", "client's hostname")
}
